package com.beiming.libra.controller;

import com.beiming.libra.common.enums.ErrorCode;
import com.beiming.libra.domain.dto.requestdto.AnswerRequestDTO;
import com.beiming.libra.domain.dto.requestdto.ProblemRequestDTO;
import com.beiming.libra.domain.dto.responsedto.AnswerResponseDTO;
import com.beiming.libra.domain.dto.responsedto.CaseProblemAndAnswerResponseDTO;
import com.beiming.libra.helper.Result;
import com.beiming.libra.service.ArbitrationCaseAnswerService;
import com.beiming.libra.service.ArbitrationCaseProblemService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @title 问题单接口
 * @author zhengyu
 * @create_time 2018/6/6
 */
@RestController
@Api(value = "问题单接口", tags = "问题单接口")
@RequestMapping("/api/arbitrationCaseProblem")
@Slf4j
public class ArbitrationCaseProblemController {

  @Resource
  private ArbitrationCaseProblemService arbitrationCaseProblemService;
  @Resource
  private ArbitrationCaseAnswerService arbitrationCaseAnswerService;

  @GetMapping("/problemList/{caseId}")
  @ApiOperation(value = "获取问题单信息", notes = "获取问题单信息")
  public Result<List<CaseProblemAndAnswerResponseDTO>> listArbitrationCaseProblems(@ApiParam(value = "仲裁申请表id" , required = true) @PathVariable("caseId") String caseId) {
    if (StringUtils.isEmpty(caseId)) {
      return Result.failed(ErrorCode.ILLEGAL_PARAMETER, "caseId参数必传");
    }
    List<CaseProblemAndAnswerResponseDTO> arbitrationCaseProblemList = arbitrationCaseProblemService.listArbitrationCaseProblems(
        caseId);
    return Result.success(arbitrationCaseProblemList);
  }

  @GetMapping("/problem/{id}")
  @ApiOperation(value = "精确获取问题单信息", notes = "获取问题单信息")
  public Result<CaseProblemAndAnswerResponseDTO> arbitrationCaseProblem(@ApiParam(value = "问题单id" , required = true) @PathVariable("id") String id) {
    if (StringUtils.isEmpty(id)) {
      return Result.failed(ErrorCode.ILLEGAL_PARAMETER, "id参数必传");
    }
    CaseProblemAndAnswerResponseDTO andAnswerResponseDTO = arbitrationCaseProblemService.getArbitrationCaseProblem(
        id);
    return Result.success(andAnswerResponseDTO);
  }


  @ApiOperation("批量保存问题单信息")
  @PostMapping("")
  public Result createArbitrationCaseProblems(@RequestBody ProblemRequestDTO arbitrationCaseProblem) {
    arbitrationCaseProblemService.saveArbitrationCaseProblems(arbitrationCaseProblem);
    return Result.success();
  }

  @ApiOperation("回答问题")
  @PostMapping("/answer")
  public Result<AnswerResponseDTO> answerProblem(@RequestBody AnswerRequestDTO answer) {
    AnswerResponseDTO answerResponseDTO = arbitrationCaseAnswerService.answerProblem(answer);
    return Result.success(answerResponseDTO);
  };
}
